var g = Graphics.createArrayBuffer(16,16,8);
g.dump = _=>{
  var s = "";
  var b = new Uint8Array(g.buffer);
  var n = 0;
  for (var y=0;y<g.getHeight();y++) {
    s+="\n";
    for (var x=0;x<g.getWidth();x++) 
      s+=".:/#"[b[n++]];
  }
  return s;
}
g.print = _=>{
  print("`"+g.dump()+"`");
}
var ok = true;
function SHOULD_BE(a) {
  var b = g.dump();
  if (a!=b) {
    console.log("GOT :"+b+"\nSHOULD BE:"+a+"\n================");
    ok = false;
  }
}

g.clear();
g.setColor(3);
img = E.toString([8,8,1,
0b11111111,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b11111111]);
g.drawImage(img,0,0);
img2 = E.toUint8Array(img);
g.drawImage(img2,8,8);
//g.print();
SHOULD_BE(`
########........
#......#........
#......#........
#......#........
#......#........
#......#........
#......#........
########........
........########
........#......#
........#......#
........#......#
........#......#
........#......#
........#......#
........########`);

g.setBgColor(2);
g.clear();
img = E.toString([8,8,1|128,0/*transparent col*/,
0b11111111,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b11111111]);
g.drawImage(img,4,4);
//g.print();
SHOULD_BE(`
////////////////
////////////////
////////////////
////////////////
////########////
////#//////#////
////#//////#////
////#//////#////
////#//////#////
////#//////#////
////#//////#////
////########////
////////////////
////////////////
////////////////
////////////////`);

result = ok;
